package net.kelissa.jenetic.impl.mutator;

import java.util.List;

import net.kelissa.jenetic.Gene;
import net.kelissa.jenetic.Mutator;
import net.kelissa.jenetic.RandomUtil;

public class MutatorBase implements Mutator
{

  private boolean mutateOnlyOne = true;

  private double mutateRate = 0.1;

  @Override
  public void mutate(List<Gene> genes)
  {
    if (this.mutateOnlyOne)
    {
      Gene allele = RandomUtil.getRandom(genes);
      allele.mutate();
    } else
    {
      for (int i = 0; i < genes.size(); i++)
      {
        if (RandomUtil.getRandomDouble() < this.mutateRate)
        {
          genes.get(i).mutate();
        }
      }
    }
  }

  // ------------------------------------
  public boolean isMutateOnlyOne()
  {
    return mutateOnlyOne;
  }

  public void setMutateOnlyOne(boolean mutateOnlyOne)
  {
    this.mutateOnlyOne = mutateOnlyOne;
  }

  public double getMutateRate()
  {
    return mutateRate;
  }

  public void setMutateRate(double mutateRate)
  {
    this.mutateRate = mutateRate;
  }

}
